<template>
  <el-dropdown trigger="click" @command="handleSetSize">
    <div>
      <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of appidList" :key="item.value" :disabled="size===item.value" :command="item.value">
        {{ item.key }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import {allApps} from "@/api/chatgpt/setting";
import {getAppId, setAppId, removeAppId, removeAppName, setAppName, getAppName} from '@/utils/app'

export default {
  data() {
    return {
      appidList: []
    }
  },
  computed: {
    size() {
      return this.$store.getters.size
    }
  },
  created() {
    this.allAppsFun()
  },
  methods: {
    allAppsFun() {
      this.loading = true
      allApps().then(response => {
        if (response.code == 200) {
          this.appidList = response.data
        }
      });
    },
    handleSetSize(appid) {
      setAppId(appid)
      this.refreshView()
      this.$message({
        message: 'APP切换成功',
        type: 'success'
      })
    },
    refreshView() {

      // In order to make the cached page re-rendered
      this.$store.dispatch('tagsView/delAllCachedViews', this.$route)

      const {fullPath} = this.$route

      this.$nextTick(() => {
        this.$router.replace({
          path: '/redirect' + fullPath
        })
      })
    }
  }

}
</script>
